package com.libary.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.libary.dto.User;
import com.libary.service.Impl.UserServiceImpl;
@Controller(value = "user")
@RequestMapping(value = "user")
public class UserController {
	
	@Autowired
	private UserServiceImpl userService;
	
	@RequestMapping(value = "/Login", method = RequestMethod.POST)
	public ModelAndView LoginCheck(@ModelAttribute User loginUser){
		 ModelAndView mav = new ModelAndView();
		if(userService.loginCheck(loginUser)){
			
			User user = userService.getUserInfo(loginUser);
			mav.setViewName("LoginSucsess");
			mav.addObject(user);
			return mav;
		} else {
			mav.setViewName("LoginFailed");
			return mav;
		}
		
	}
}
